﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using GZNest.Entity.Spin.Biz;
using GZNest.Biz.IService.Spin.Biz;
using GZNest.Biz.Service.Spin.Biz;

namespace GZNest.Web.Areas.Spin.Controllers
{
    public class ProductionOrderController : Controller
    {
        private IProductionOrderService productionOrderService;
        public ProductionOrderController()
        {
            productionOrderService = new ProductionOrderService();
        }


        // GET: Spin/ProductionOrders
        public ActionResult Index()
        {
            return View(productionOrderService.FindAll());
        }

        // GET: Spin/ProductionOrders/Details/5
        public ActionResult Details(int id)
        {
          
            ProductionOrder productionOrder = productionOrderService.Find(id);
            if (productionOrder == null)
            {
                return HttpNotFound();
            }
            return View(productionOrder);
        }

        // GET: Spin/ProductionOrders/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: Spin/ProductionOrders/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,Description,OrderLength,CompletedLenght,DailyProduction,Unit,CreatedDateTime,LastModifiedDatetime,Status")] ProductionOrder productionOrder)
        {
            if (ModelState.IsValid)
            {
                productionOrderService.Add(productionOrder);
                return RedirectToAction("Index");
            }

            return View(productionOrder);
        }

        // GET: Spin/ProductionOrders/Edit/5
        public ActionResult Edit(int id)
        {
            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            ProductionOrder productionOrder = productionOrderService.Find(id);
            if (productionOrder == null)
            {
                return HttpNotFound();
            }
            return View(productionOrder);
        }

        // POST: Spin/ProductionOrders/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "Id,Description,OrderLength,CompletedLenght,DailyProduction,Unit,CreatedDateTime,LastModifiedDatetime,Status")] ProductionOrder productionOrder)
        {
            if (ModelState.IsValid)
            {
                productionOrderService.Update(productionOrder);
                
                return RedirectToAction("Index");
            }
            return View(productionOrder);
        }

        // GET: Spin/ProductionOrders/Delete/5
        public ActionResult Delete(int id)
        { 
            ProductionOrder productionOrder = productionOrderService.Find(id);
            if (productionOrder == null)
            {
                return HttpNotFound();
            }
            return View(productionOrder);
        }

        // POST: Spin/ProductionOrders/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            ProductionOrder productionOrder = productionOrderService.Find(id);

            productionOrderService.Delete(productionOrder);

            return RedirectToAction("Index");
        }
    }
}
